package org.jeecg.modules.gongqiang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.gongqiang.entity.*;
import org.jeecg.modules.gongqiang.mapper.AccountPoolMapper;
import org.jeecg.modules.gongqiang.mapper.AccountVarietyMapper;
import org.jeecg.modules.gongqiang.mapper.OrderIndexArmMapper;
import org.jeecg.modules.gongqiang.mapper.PlatformAccountMapper;
import org.jeecg.modules.gongqiang.service.IAccountVarietyService;
import org.jeecg.modules.gongqiang.service.IOrderIndexArmService;
import org.jeecg.modules.gongqiang.service.IPlatformAccountService;
import org.jeecg.modules.gongqiang.vo.AccountVarietyParams;
import org.jeecg.modules.gongqiang.vo.NumberPlatformParams;
import org.jeecg.modules.gongqiang.vo.PlatformAccountParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 平台账号对应关系
 * @Author: jeecg-boot
 * @Date:   2024-10-28
 * @Version: V1.0
 */
@Service
public class PlatformAccountServiceImpl extends ServiceImpl<PlatformAccountMapper, PlatformAccount> implements IPlatformAccountService {

    @Autowired
    private IAccountVarietyService accountVarietyService;

    @Resource
    private AccountPoolMapper accountPoolMapper;


    @Override
    public Result<String> deleteAll(String id)
    {
        this.removeById(id);
        LambdaQueryWrapper<AccountVariety> queryWrapperAccountVariety=new LambdaQueryWrapper<>();
        queryWrapperAccountVariety.eq(AccountVariety::getPlatformAccountId,id);
        List<AccountVariety> arrayList=accountVarietyService.list(queryWrapperAccountVariety);
        for(AccountVariety temp:arrayList)
        {
            accountVarietyService.deleteAll(temp.getId());
        }

        return Result.OK("删除成功!");
    }

    @Override
    public PlatformAccountParams searhInfos(String id)
    {
        LambdaQueryWrapper< PlatformAccount> queryWrapperPlatformAccount=new LambdaQueryWrapper<>();
        queryWrapperPlatformAccount.eq(PlatformAccount::getNumberPlatformId,id);
        List<PlatformAccount> arrayList=this.list(queryWrapperPlatformAccount);
        List<AccountVarietyParams> accountVarietyParamsArray=new ArrayList<>();
        for(PlatformAccount temp:arrayList)
        {
            AccountVarietyParams accountVarietyParams=new AccountVarietyParams();
            accountVarietyParams=accountVarietyService.searhInfos(temp.getId());
            AccountPool accountPool=accountPoolMapper.selectById(temp.getAccountId());
            if(oConvertUtils.isEmpty(accountPool))
            {
                accountVarietyParams.setAccountName(null);
            }
            else
            {
                accountVarietyParams.setAccountName(accountPool.getAccountName());
            }

            accountVarietyParamsArray.add(accountVarietyParams);
        }
        PlatformAccountParams platformAccountParams=new PlatformAccountParams();
        platformAccountParams.setAccountVarietyParamsList(accountVarietyParamsArray);
        return platformAccountParams;
    }
}
